// src/pages/Home/router/SiderMenusRoute.js
import React from 'react';
import { Menu } from 'antd';
import { useNavigate, useLocation } from 'react-router-dom';
import {
  UserOutlined,
  TeamOutlined,
  SafetyCertificateOutlined,
  DatabaseOutlined,
  SendOutlined,
  SettingOutlined,
  BarChartOutlined,
  LockOutlined
} from '@ant-design/icons';
import './SiderMenusRoute.css';

const SiderMenusRoute = () => {
  const navigate = useNavigate();
  const location = useLocation();

  const handleClick = ({ key }) => {
    switch (key) {
      case 'user-management':
        navigate('/user-management');
        break;
      case 'department-management':
        navigate('/department-management');
        break;
      case 'role-management':
        navigate('/role-management');
        break;
      case 'data-source':
        navigate('/data-source');
        break;
      case 'content-distribution':
        navigate('/content-distribution');
        break;
      case 'system-operations':
        navigate('/system-operations');
        break;
      case 'data-analysis':
        navigate('/data-analysis');
        break;
      case 'metadata-driven':
        navigate('/metadata-driven');
        break;
      case 'permission-overview':
        navigate('/permission-overview');
        break;
      default:
        navigate('/');
    }
  };

  const getSelectedKey = () => {
    const path = location.pathname;
    if (path.includes('user-management')) return 'user-management';
    if (path.includes('department-management')) return 'department-management';
    if (path.includes('role-management')) return 'role-management';
    if (path.includes('data-source')) return 'data-source';
    if (path.includes('content-distribution')) return 'content-distribution';
    if (path.includes('system-operations')) return 'system-operations';
    if (path.includes('data-analysis')) return 'data-analysis';
    if (path.includes('metadata-driven')) return 'metadata-driven';
    if (path.includes('permission-overview')) return 'permission-overview';
    return 'dashboard';
  };

  const menuItems = [
    {
      key: 'dashboard',
      icon: <UserOutlined />,
      label: '首页',
    },
    {
      key: 'user-management',
      icon: <UserOutlined />,
      label: '用户管理',
    },
    {
      key: 'department-management',
      icon: <TeamOutlined />,
      label: '部门管理',
    },
    {
      key: 'role-management',
      icon: <SafetyCertificateOutlined />,
      label: '角色管理',
    },
    {
      key: 'data-source',
      icon: <DatabaseOutlined />,
      label: '数据源管理',
    },
    {
      key: 'data-analysis',
      icon: <BarChartOutlined />,
      label: '数据分析',
    },
    {
      key: 'content-distribution',
      icon: <SendOutlined />,
      label: '内容分发',
    },
    {
      key: 'system-operations',
      icon: <SettingOutlined />,
      label: '系统运维',
    },
    {
      key: 'metadata-driven',
      icon: <DatabaseOutlined />,
      label: '元数据驱动',
    },
    {
      key: 'permission-overview',
      icon: <LockOutlined />,
      label: '权限概览',
    }
  ];

  return (
    <Menu
      mode="inline"
      selectedKeys={[getSelectedKey()]}
      onClick={handleClick}
      items={menuItems}
      style={{ height: '100%', borderRight: 0 }}
      theme="dark"
      className="sider-menu"
    />
  );
};

export default SiderMenusRoute;
